home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 April: Mac OS SDK / Dev.CD Apr 99 SDK1.toast / Development Kits / Apple Shared Library Manager / ASLM Examples / Example Tools / Sources / TPoolNotifierExample.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-19  |  2.5 KB  |  81 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        TPoolNotifierExample.h
  3.  
  4.     Contains:    The Shared Library Manager provides the TPoolNotifier class to assist
  5.                 in automatically “growing” a pool when the pool comes dangerously close
  6.                 to running out of memory. This is an example of TPoolNotifier. 
  7.  
  8.     Copyright:    © 1993 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12. #ifndef __TPOOLNOTIFIEREXAMPLE__
  13. #define __TPOOLNOTIFIEREXAMPLE__
  14.  
  15. ///————————————————————————————————————————————————————————————————————————————————————
  16. ///    TMyPoolNotifier
  17. ///
  18. /// This is a TPoolNotifier subclass that overrides the Notify and GrowBy routines
  19. /// simply for the sake of displaying a message.
  20. ///————————————————————————————————————————————————————————————————————————————————————
  21.  
  22. class TMyPoolNotifier : public TPoolNotifier {
  23.     public:
  24.                         TMyPoolNotifier(unsigned short growBy = 10, 
  25.                                           unsigned short minGrow = 128);
  26.         virtual            ~TMyPoolNotifier();
  27.         
  28.         // TPoolNotifier methods that we override
  29.         virtual void     Notify( EventCode, OSErrParm = kNoError, void *theData=NULL );
  30.         virtual size_t    GrowBy( TMemoryPool*, size_t );
  31.         
  32.     private:
  33.         GlobalWorld    fWorld;     // so we can setup our world when called at system task time
  34. };
  35.  
  36. ///————————————————————————————————————————————————————————————————————————————————————
  37. ///    TMyPoolNotifier IMPLEMENTATION
  38. ///————————————————————————————————————————————————————————————————————————————————————
  39.  
  40.     TMyPoolNotifier::TMyPoolNotifier(unsigned short growBy, unsigned short minGrow) :
  41.                      TPoolNotifier( growBy , minGrow )
  42.     {
  43.         fWorld = GetCurrentGlobalWorld();
  44.     }
  45.     
  46.     TMyPoolNotifier::~TMyPoolNotifier()
  47.     {
  48.     }
  49.     
  50.     /// notify the user when we reached the low and high marks
  51.     
  52.     void TMyPoolNotifier::Notify( EventCode evtCode, OSErrParm err, void *thePool )
  53.     {
  54.         GlobalWorld savedWorld = SetCurrentGlobalWorld(fWorld);
  55.         
  56.         cout << "TMyPoolNotifier::Notify called: ";
  57.         cout << "thePool = " << (void*)thePool << endl;
  58.             
  59.         if( evtCode == kLowPoolMemoryEvent )
  60.             cout << "Reached LOW MEMORY indicator" << endl;
  61.         else
  62.             cout << "Reached HIGH MEMORY indicator" << endl;
  63.     
  64.         TPoolNotifier::Notify( evtCode, err, thePool );    // call the default
  65.         
  66.         SetCurrentGlobalWorld(savedWorld);
  67.     }
  68.     
  69.     size_t TMyPoolNotifier::GrowBy( TMemoryPool* thePool, size_t theSize)
  70.     {
  71.         GlobalWorld savedWorld = SetCurrentGlobalWorld(fWorld);
  72.         
  73.         cout << "TMyPoolNotifier::GrowBy called: ";
  74.         cout << "thePool = " << (void*)thePool << " theSize = " << theSize << endl;
  75.         
  76.         SetCurrentGlobalWorld(savedWorld);
  77.  
  78.         return TPoolNotifier::GrowBy( thePool, theSize ); // call the default
  79.     }
  80.  
  81. #endif